{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "initial centroids are: [[1.84801320e+01 5.63436000e-01 1.13821000e+01 8.21040000e-02\n",
      "  1.52444880e+01 3.71712000e-01 6.48000000e+00 5.34296400e+00\n",
      "  4.26612842e+01]\n",
      " [2.64601890e+01 4.79520000e-03 3.44110000e-01 3.76310000e-01\n",
      "  3.23556480e+00 8.51840000e-02 2.10600000e+01 2.78577000e-01\n",
      "  4.58723132e+01]\n",
      " [1.94392218e+01 1.79820000e-03 2.83758400e-03 1.91576000e-02\n",
      "  5.25117607e+00 6.89216000e-02 3.11058396e+01 7.70015400e-03\n",
      "  4.45796912e+01]\n",
      " [2.58675181e+01 7.19280000e-02 3.94932400e+00 4.78940000e-02\n",
      "  3.74112180e+00 2.32320000e-02 6.93000000e+00 1.21502430e+01\n",
      "  4.47918532e+01]]\n",
      "group result iteration 1 [226. 177. 435. 134.]\n",
      "group result iteration 2 [194. 218. 435. 125.]\n",
      "group result iteration 3 [155. 257. 435. 125.]\n",
      "group result iteration 4 [139. 267. 441. 125.]\n",
      "group result iteration 5 [130. 264. 453. 125.]\n",
      "group result iteration 6 [127. 234. 486. 125.]\n",
      "group result iteration 7 [117. 233. 497. 125.]\n",
      "group result iteration 8 [109. 240. 498. 125.]\n",
      "group result iteration 9 [102. 246. 499. 125.]\n",
      "group result iteration 10 [ 98. 249. 500. 125.]\n",
      "Input_weight_Kmeans Finish!\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEHCAYAAABBW1qbAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/d3fzzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAufklEQVR4nO3de5wU1Zn/8c/DMIAyiIJKkNtgAirQA8goEY0OYlCj8UJk1USXRDf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gzJrKQRIDg1ubcucGJy9ixcPrpUUfUkBQuv/zyfZbV1dVR0sw918rKSiorKzMSw2WXXQYEFatNicfjlJWVMWHChIzsr9gV3ZXC6acHdQhdwm9eVha8z4V/QCleibquCy+EG28Mpqee2rFGEPfddx8VFRWMHj2aiy++GIANGzbwuc99jmOOOYZjjjmGP/7xjwDMmDGDSy65hKqqKg4//HBuv/12AK6//nr+9re/MWbMGK699lri8TgTJ07k85//PLFYjJ07d/KlL32JWCzG2LFjWbBgARAcqM8880wANm3axOTJkxk7dixf+cpXaG4I4HvvvZfhw4dz0kkn1ceViO22224D4Pbbb2fEiBFUVFRwwQUXsGrVKmbOnMkPf/hDxowZw/PPP88TTzzB+PHjGTt2LKeccgoffPBBi9+xrWWV+nur4xvf+AaxWIyKigruuOOO+mV33HEHRx99NLFYjLfeeguAl19+mQkTJjB27FgmTJjAihUrgODKaMqUKZx22mkMGzaM6667rn47d999N8OHD6eqqoovf/nL9VdQGzdubDW+dnH3vP0ZN26ct0dtrftJJ7n37u3+xBPB+6gsWLAgup3noEIqj2XLltW/vvrq4G+uuZ9Ro9y7dHEParqCny5d3EeMqG32M1df3fy+ly5d6sOHD/cNGza4u/umTZvc3f3CCy/0559/3t3dV69e7UceeaS7u994441+3HHH+c6dO33Dhg3ep08f3717t7/77rs+cuTI+u0uWLDA999/f3/nnXfc3f22227zL37xi+7uvnz5ch80aJDv2LHDFyxY4GeccYa7u1955ZX+ne98x93d58yZ40B9XAnvv/++Dxo0yNevX++7du3yCRMm+BVXXFEf26233urbtm3z/v37+86dO93dffPmzSnLEz788EPfu3evu7v//Oc/92uuuabF79jWskp25513+pQpU3zPnj0pnx0yZIjffvvt7u7+05/+1C+99FJ3d9+6dWv9uvPmzfMpU6a4u/u9997rQ4cO9S1btviOHTt88ODBvmbNGn/vvfd8yJAhvmnTJt+9e7efcMIJ9eVy3nnntRqfe+rfYQKw2Js5rhbd7SMIWhmddho89xyccIJaHUn0ampg797UeXv3BvMPabIvy5b94Q9/4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MF4HP1a2fYJwC8B3P0tYDWQSArz3X2ru+8k6GtpSAe+g+QpXSlIPvgRQb839ybNqyU8qQk7SeuWtGxX0uu9Se/3kvo337iPFyc40F7p7k8nLzCzKoIurJtircTfVgZ8zt1XNIphfKMYvgAcAoxz9z1hL7OtDVPZUqzJ5VaHjg9FSVcKkvPCM+OHCSptE1YR3K6BoK/90nZseqqZdQnrGQ4HVgBPA/8admuOmQ231ge4WQScZGYHh5XQFwLPtSGOj4BeSe+fBq4Mkx1mNraZz/UmGIdiT1g3kDizb7y9ZAsJkgnhbaPBBN9bBFBSkPzxfSC5FdLPCQ7ELwONz6DTtYLg4D0XuCy8bfILglsnfwkrZ/+XVs6Yw1GvbgAWAK8Df3H3tnRjvAAYkahoBm4iSHJLwhhuauZzDwCVZraY4ED/VhjPJoK6kKWNK7iBO4ESM3sD+D/gi+FtNhFAvaSKiEgSXSmIiEg9JQUREamnpCAiIvWUFEREpJ6SgoiI1FNSEBGRekoKIiJST0lBRETq/X+gE3YB9O1OSgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "****************************** model performance ******************************\n",
      "Homogeneity Score         (均一性):  0.7279176053762155\n",
      "Completeness Score        (完整性):  0.7201963481323292\n",
      "V-Measure Score           (V量):  0.7240363921126832\n",
      "Adjusted Rand Score       (调整后兰德指数):  0.7173549829485324\n",
      "Adjusted Mutual Info Score(调整后的共同信息):  0.7229358266335765\n",
      "Calinski Harabasz Score:  (方差比指数)  827.966424309716\n",
      "Silhouette Score          (轮廓分数):  0.6363246802914886\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "from kmeans_input_weight_class import *\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "kmeans_input_weight=kmeans_input_weight()\n",
    "\n",
    "orig_data = pd.read_excel('test4.xlsx')\n",
    "orig_data.dropna(inplace=True)\n",
    "\n",
    "x_orig_data = orig_data.drop('TRUE VALUE',axis=1)\n",
    "y_label = orig_data['TRUE VALUE']\n",
    "\n",
    "x_data=np.array(x_orig_data)\n",
    "\n",
    "n_iters = 10\n",
    "n_clusters = 4\n",
    "centroids = kmeans_input_weight.plus_plus(x_data, n_clusters)  # centroilds initialization\n",
    "dist = np.zeros((x_data.shape[0],n_clusters), dtype=float)\n",
    "\n",
    "print(\"initial centroids are:\",centroids)\n",
    "\n",
    "w = pd.read_excel('weight.xlsx')  # input weight from weight.xlsx flie\n",
    "w = np.array(w)\n",
    "tol=1e-10\n",
    "count=0\n",
    "C = np.zeros(n_iters)\n",
    "    \n",
    "for i in range(n_iters):\n",
    "    count+=1\n",
    "    group= np.zeros(n_clusters)\n",
    "    old_centroids=centroids.copy()\n",
    "    for j in range(x_data.shape[0]):\n",
    "        distance = np.power(x_data[j,:]-centroids, 2)  \n",
    "        distance = np.sum(w*distance, axis=1)\n",
    "        distance = np.sqrt(distance) \n",
    "        dist[j,:] = distance\n",
    "    idx = np.argmin(dist, axis=1)   # predicted group index\n",
    "\n",
    "    for k in range(n_clusters):\n",
    "        d = x_data[idx==k, :]\n",
    "        group[k]=d.shape[0]\n",
    "        centroids[k,:] = np.mean(d, axis=0)\n",
    "    print('group result iteration', count, group)   # group number after each iterration\n",
    "    centroid_change=kmeans_input_weight.sqrsum(centroids - old_centroids)\n",
    "    C[i]=centroid_change\n",
    "    if centroid_change <= tol:\n",
    "            break\n",
    "print(\"Input_weight_Kmeans Finish!\")\n",
    "\n",
    "plt.plot(np.arange(n_iters)+1, C, color='blue', marker='o', markersize=5, label='centroid distance change')\n",
    "plt.grid(True)\n",
    "plt.xlabel(\"Number of iteration\")\n",
    "plt.ylabel(\"centroid distance change\")\n",
    "plt.legend(loc='best')\n",
    "plt.show()\n",
    "\n",
    "print(kmeans_input_weight.get_marks(x_data, y_label, idx))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
